package com.ruoyi.web.controller.dictionary;

import java.text.SimpleDateFormat;
import java.util.List;

import com.ruoyi.domain.SysMatClassificationType;
import com.ruoyi.domain.SysMatDataType;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.service.ISysMatDataTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.SysMatDetailsType;
import com.ruoyi.service.ISysMatDetailsTypeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 材料详情Controller
 * 
 * @author ruoyi
 * @date 2020-07-03
 */
@Controller
@RequestMapping("/ruoyi/details")
public class SysMatDetailsTypeController extends BaseController
{
    private String prefix = "ruoyi/details";

    @Autowired
    private ISysMatDetailsTypeService sysMatDetailsTypeService;
    @Autowired
    private ISysMatDataTypeService sysMatDataTypeService;

    @RequiresPermissions("ruoyi:details:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
     * 查询材料详情列表
     */
    @RequiresPermissions("ruoyi:details:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(String matDataType)
    {
        startPage();
        List<SysMatDetailsType> list = sysMatDetailsTypeService.selectSysMatDetailsTypeLists(matDataType);
        return getDataTable(list);
    }

    /**
     * 导出材料详情列表
     */
    @RequiresPermissions("ruoyi:details:export")
    @Log(title = "材料详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysMatDetailsType sysMatDetailsType)
    {
        List<SysMatDetailsType> list = sysMatDetailsTypeService.selectSysMatDetailsTypeList(sysMatDetailsType);
        ExcelUtil<SysMatDetailsType> util = new ExcelUtil<SysMatDetailsType>(SysMatDetailsType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 新增材料详情
     */
    @GetMapping("/add/{matDataType}")
    public String add(@PathVariable("matDataType") String matDataType, ModelMap mmap)
    {
        mmap.put("matDataType",matDataType);
        return prefix + "/add";
    }

    /**
     * 新增保存材料详情
     */
    @RequiresPermissions("ruoyi:details:add")
    @Log(title = "材料详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysMatDetailsType sysMatDetailsType)
    {
        //获取创建者
        sysMatDetailsType.setMatDetailsCreateBy(ShiroUtils.getLoginName());
        //获取创建时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd  hh:mm:ss");
        return toAjax(sysMatDetailsTypeService.insertSysMatDetailsType(sysMatDetailsType));
    }

    /**
     * 修改材料详情
     */
    @GetMapping("/edit/{matDetailsId}")
    public String edit(@PathVariable("matDetailsId") Integer matDetailsId, ModelMap mmap)
    {
        SysMatDetailsType sysMatDetailsType = sysMatDetailsTypeService.selectSysMatDetailsTypeById(matDetailsId);
        mmap.put("sysMatDetailsType", sysMatDetailsType);
        return prefix + "/edit";
    }

    /**
     * 修改保存材料详情
     */
    @RequiresPermissions("ruoyi:details:edit")
    @Log(title = "材料详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysMatDetailsType sysMatDetailsType)
    {
        //获取创建者
        sysMatDetailsType.setMatDetailsCreateBy(ShiroUtils.getLoginName());
        //获取创建时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd  hh:mm:ss");
        return toAjax(sysMatDetailsTypeService.updateSysMatDetailsType(sysMatDetailsType));
    }

    /**
     * 删除材料详情
     */
    @RequiresPermissions("ruoyi:details:remove")
    @Log(title = "材料详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysMatDetailsTypeService.deleteSysMatDetailsTypeByIds(ids));
    }

    /**
     * 材料详情
     */
    @RequiresPermissions("ruoyi:details:details")
    @GetMapping("/details/{matDataType}")
    public String detail(@PathVariable("matDataType") String matDataType, ModelMap mmap) {
        mmap.put("matDataType",matDataType);
        return prefix + "/type";
    }
}
